'use strict';

const { Service } = require('egg');

class ShopService extends Service {
  /**
   *  create a shop model
   * @param {Shop} shop  shop model
   */
  async create(shop) {
    let newShop = new this.ctx.model.Shop();
    newShop = Object.assign(newShop, shop);
    newShop.save();
  }
  /**
   * find  a shop by shop id
   * @param {String } shopId  shop id 
   */
  async findById(shopId) {
    return this.ctx.model.Shop.find({
      shopId: shopId
    });
  }

  async findAll() {
    return this.ctx.model.Shop.find({});
  }

  async update(shopId, shop) {
    console.log('update', shop);
    this.ctx.model.Shop.update(shop, { shopId: shopId}, (err)=> {
      if (err) {
        console.log(err);
      }
    });
  }
}

module.exports = ShopService;
